<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - string.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2006  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_STRINg_
<font color='#0000FF'>#define</font> DLIB_STRINg_ 

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='string_abstract.h.html'>string_abstract.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>sstream<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../algs.h.html'>../algs.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>string<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>iostream<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>iomanip<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../error.h.html'>../error.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../assert.h.html'>../assert.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../uintn.h.html'>../uintn.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>cctype<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>algorithm<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>vector<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../enable_if.h.html'>../enable_if.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> <font color='#0000FF'>typename</font> disable_if<font color='#5555FF'>&lt;</font>is_same_type<font color='#5555FF'>&lt;</font>charT,<font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font>,std::string<font color='#5555FF'>&gt;</font>::type <b><a name='narrow'></a>narrow</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::string temp;
        temp.<font color='#BB00BB'>reserve</font><font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        std::string::size_type i;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zero_extend_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>255</font><font face='Lucida Console'>)</font>
                temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> '<font color='#FF0000'> </font>';
            <font color='#0000FF'>else</font>
                temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> zero_extend_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str[i]<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> <font color='#0000FF'>typename</font> enable_if<font color='#5555FF'>&lt;</font>is_same_type<font color='#5555FF'>&lt;</font>charT,<font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font>,std::string<font color='#5555FF'>&gt;</font>::type <b><a name='narrow'></a>narrow</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str
    <font face='Lucida Console'>)</font>
    <b>{</b> 
        <font color='#0000FF'>return</font> str;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='tolower'></a>tolower</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font> temp;

        temp.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font>::size_type i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            temp[i] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>char</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>str[i]<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> temp;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='toupper'></a>toupper</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font> temp;

        temp.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font>::size_type i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            temp[i] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>char</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>toupper</font><font face='Lucida Console'>(</font>str[i]<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> temp;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> <b><a name='strings_equal_ignore_case'></a>strings_equal_ignore_case</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str1,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str2
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>str1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> str2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font>::size_type i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> str1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>str1[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>str2[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>

        <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> <b><a name='strings_equal_ignore_case'></a>strings_equal_ignore_case</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str1,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str2
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font>::size_type i;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> str1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// if we hit the end of str2 then the strings aren't the same length
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>str2[i] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\0</font>'<font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>str1[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>str2[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>

        <font color='#009900'>// This happens when str2 is longer than str1
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>str2[i] <font color='#5555FF'>!</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\0</font>'<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

        <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> <b><a name='strings_equal_ignore_case'></a>strings_equal_ignore_case</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str1,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str2
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>strings_equal_ignore_case</font><font face='Lucida Console'>(</font>str2, str1<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> <b><a name='strings_equal_ignore_case'></a>strings_equal_ignore_case</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str1,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str2,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> num
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>str1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> str2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>str1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> num <font color='#5555FF'>|</font><font color='#5555FF'>|</font> str2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> num<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font>::size_type i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> str1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> i <font color='#5555FF'>&lt;</font> num; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>str1[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>str2[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>

        <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> <b><a name='strings_equal_ignore_case'></a>strings_equal_ignore_case</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str1,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str2,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> num
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font>::size_type i;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> str1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> i <font color='#5555FF'>&lt;</font> num; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// if we hit the end of str2 then the strings aren't the same length
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>str2[i] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\0</font>'<font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>str1[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>str2[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>

        <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> <b><a name='strings_equal_ignore_case'></a>strings_equal_ignore_case</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str1,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font>,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str2,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> num
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>strings_equal_ignore_case</font><font face='Lucida Console'>(</font>str2, str1, num<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='cast_to_string_error'></a>cast_to_string_error</b> : <font color='#0000FF'>public</font> error
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <b><a name='cast_to_string_error'></a>cast_to_string_error</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>:error<font face='Lucida Console'>(</font>ECAST_TO_STRING<font face='Lucida Console'>)</font> <b>{</b><b>}</b>
    <b>}</b>;

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::string <b><a name='cast_to_string'></a>cast_to_string</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> T<font color='#5555FF'>&amp;</font> item 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::ostringstream sout;
        sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> item;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>sout<font face='Lucida Console'>)</font>
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>cast_to_string_error</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#009900'>// don't declare this if we are using mingw because it apparently doesn't
</font>    <font color='#009900'>// support iostreams with wchar_t?
</font><font color='#0000FF'>#if</font> <font color='#5555FF'>!</font><font face='Lucida Console'>(</font>defined<font face='Lucida Console'>(</font>__MINGW32__<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>__GNUC__ <font color='#5555FF'>&lt;</font> <font color='#979000'>4</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::wstring <b><a name='cast_to_wstring'></a>cast_to_wstring</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> T<font color='#5555FF'>&amp;</font> item 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::basic_ostringstream<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>wchar_t</u></font><font color='#5555FF'>&gt;</font> sout;
        sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> item;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>sout<font face='Lucida Console'>)</font>
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>cast_to_string_error</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>
<font color='#0000FF'>#endif</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> std::string <b><a name='pad_int_with_zeros'></a>pad_int_with_zeros</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>int</u></font> i,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width <font color='#5555FF'>=</font> <font color='#979000'>6</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::ostringstream sout;
        sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> std::<font color='#BB00BB'>setw</font><font face='Lucida Console'>(</font>width<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> std::<font color='#BB00BB'>setfill</font><font face='Lucida Console'>(</font>'<font color='#FF0000'>0</font>'<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> i;
        <font color='#0000FF'>return</font> sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='string_cast_error'></a>string_cast_error</b> : <font color='#0000FF'>public</font> error
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <b><a name='string_cast_error'></a>string_cast_error</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> str<font face='Lucida Console'>)</font>:
            error<font face='Lucida Console'>(</font>ESTRING_CAST,"<font color='#CC0000'>string cast error: invalid string = '</font>" <font color='#5555FF'>+</font> str <font color='#5555FF'>+</font> "<font color='#CC0000'>'</font>"<font face='Lucida Console'>)</font> <b>{</b><b>}</b>
    <b>}</b>;

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>struct</font> <b><a name='string_cast_helper'></a>string_cast_helper</b>
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font> <font color='#0000FF'>typename</font> charT, <font color='#0000FF'>typename</font> traits, <font color='#0000FF'>typename</font> alloc <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>static</font> <font color='#0000FF'>const</font> T <b><a name='cast'></a>cast</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
            basic_istringstream<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>sin</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
            T temp;
            sin <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> temp;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>sin<font face='Lucida Console'>)</font> <font color='#0000FF'>throw</font> <font color='#BB00BB'>string_cast_error</font><font face='Lucida Console'>(</font><font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sin.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::char_traits<font color='#5555FF'>&lt;</font>charT<font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>eof</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>throw</font> <font color='#BB00BB'>string_cast_error</font><font face='Lucida Console'>(</font><font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;   
            <font color='#0000FF'>return</font> temp;
        <b>}</b>
    <b>}</b>;

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> C, <font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> A<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>struct</font> <b><a name='string_cast_helper'></a>string_cast_helper</b><font color='#5555FF'>&lt;</font>std::basic_string<font color='#5555FF'>&lt;</font>C,T,A<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font>
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font> <font color='#0000FF'>typename</font> charT, <font color='#0000FF'>typename</font> traits, <font color='#0000FF'>typename</font> alloc <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>static</font> <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>C,T,A<font color='#5555FF'>&gt;</font> <b><a name='cast'></a>cast</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str
        <font face='Lucida Console'>)</font>
        <b>{</b>
            std::basic_string<font color='#5555FF'>&lt;</font>C,T,A<font color='#5555FF'>&gt;</font> temp;
            temp.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                temp[i] <font color='#5555FF'>=</font> zero_extend_cast<font color='#5555FF'>&lt;</font>C<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str[i]<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> temp;
        <b>}</b>
    <b>}</b>;

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>struct</font> <b><a name='string_cast_helper'></a>string_cast_helper</b><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>&gt;</font>
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font> <font color='#0000FF'>typename</font> charT, <font color='#0000FF'>typename</font> traits, <font color='#0000FF'>typename</font> alloc <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>static</font> <font color='#0000FF'><u>bool</u></font> <b><a name='cast'></a>cast</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> str[<font color='#979000'>0</font>] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>1</font>'<font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> str[<font color='#979000'>0</font>] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>0</font>'<font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font><font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> "<font color='#CC0000'>true</font>"<font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font><font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> "<font color='#CC0000'>false</font>"<font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

            <font color='#0000FF'>throw</font> <font color='#BB00BB'>string_cast_error</font><font face='Lucida Console'>(</font><font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>;

<font color='#0000FF'>#define</font> DLIB_STRING_CAST_INTEGRAL<font face='Lucida Console'>(</font>type<font face='Lucida Console'>)</font>                             \
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&gt;</font>                                                     \
    <font color='#0000FF'>struct</font> <b><a name='string_cast_helper'></a>string_cast_helper</b><font color='#5555FF'>&lt;</font>type<font color='#5555FF'>&gt;</font>                                 \
    <b>{</b>                                                               \
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font> <font color='#0000FF'>typename</font> charT, <font color='#0000FF'>typename</font> traits, <font color='#0000FF'>typename</font> alloc<font color='#5555FF'>&gt;</font> \
        <font color='#0000FF'>static</font> type <b><a name='cast'></a>cast</b> <font face='Lucida Console'>(</font>                                    \
            <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str        \
        <font face='Lucida Console'>)</font>                                                           \
        <b>{</b>                                                           \
            <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;                                    \
            basic_istringstream<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>sin</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;       \
            type temp;                                              \
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>2</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> str[<font color='#979000'>0</font>] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,'<font color='#FF0000'>0</font>'<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> str[<font color='#979000'>1</font>] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,'<font color='#FF0000'>x</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>   \
                sin <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> hex <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> temp;                                 \
            <font color='#0000FF'>else</font>                                                    \
                sin <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> temp;                                        \
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>sin<font face='Lucida Console'>)</font> <font color='#0000FF'>throw</font> <font color='#BB00BB'>string_cast_error</font><font face='Lucida Console'>(</font><font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;                 \
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sin.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::char_traits<font color='#5555FF'>&lt;</font>charT<font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>eof</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>throw</font> <font color='#BB00BB'>string_cast_error</font><font face='Lucida Console'>(</font><font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;     \
            <font color='#0000FF'>return</font> temp;                                            \
        <b>}</b>                                                           \
    <b>}</b>;

    <b><a name='DLIB_STRING_CAST_INTEGRAL'></a>DLIB_STRING_CAST_INTEGRAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>short</u></font><font face='Lucida Console'>)</font>
    <b><a name='DLIB_STRING_CAST_INTEGRAL'></a>DLIB_STRING_CAST_INTEGRAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>short</u></font><font face='Lucida Console'>)</font>
    <b><a name='DLIB_STRING_CAST_INTEGRAL'></a>DLIB_STRING_CAST_INTEGRAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>int</u></font><font face='Lucida Console'>)</font>
    <b><a name='DLIB_STRING_CAST_INTEGRAL'></a>DLIB_STRING_CAST_INTEGRAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font><font face='Lucida Console'>)</font>
    <b><a name='DLIB_STRING_CAST_INTEGRAL'></a>DLIB_STRING_CAST_INTEGRAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>
    <b><a name='DLIB_STRING_CAST_INTEGRAL'></a>DLIB_STRING_CAST_INTEGRAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>
    <b><a name='DLIB_STRING_CAST_INTEGRAL'></a>DLIB_STRING_CAST_INTEGRAL</b><font face='Lucida Console'>(</font>uint64<font face='Lucida Console'>)</font>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T,
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> T <b><a name='string_cast'></a>string_cast</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font>is_pointer_type<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font>::value <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> string_cast_helper<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>cast</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> T <b><a name='string_cast'></a>string_cast</b> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str<font face='Lucida Console'>)</font><b>{</b> <font color='#0000FF'>return</font> string_cast<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> T <b><a name='string_cast'></a>string_cast</b> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> <font color='#0000FF'><u>wchar_t</u></font><font color='#5555FF'>*</font> str<font face='Lucida Console'>)</font><b>{</b> <font color='#0000FF'>return</font> string_cast<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>wstring</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='string_assign'></a>string_assign</b>
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> charT,
            <font color='#0000FF'>typename</font> traits,
            <font color='#0000FF'>typename</font> alloc
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>class</font> <b><a name='string_assign_helper'></a>string_assign_helper</b>
        <b>{</b>
        <font color='#0000FF'>public</font>:
            <b><a name='string_assign_helper'></a>string_assign_helper</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str_
            <font face='Lucida Console'>)</font> : str<font face='Lucida Console'>(</font>str_<font face='Lucida Console'>)</font> <b>{</b><b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
            <b><a name='operator'></a>operator</b> <b><a name='T'></a>T</b> <font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>return</font> string_cast<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
            <b>}</b>

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str;
        <b>}</b>;

    <font color='#009900'>// -------------
</font>
        <font color='#0000FF'>class</font> <b><a name='char_assign_helper'></a>char_assign_helper</b>
        <b>{</b>
        <font color='#0000FF'>public</font>:
            <b><a name='char_assign_helper'></a>char_assign_helper</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str_
            <font face='Lucida Console'>)</font> : str<font face='Lucida Console'>(</font>str_<font face='Lucida Console'>)</font> <b>{</b><b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
            <b><a name='operator'></a>operator</b> <b><a name='T'></a>T</b> <font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>return</font> string_cast<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
            <b>}</b>

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str;
        <b>}</b>;

    <font color='#009900'>// -------------
</font>
        <font color='#0000FF'>class</font> <b><a name='wchar_t_assign_helper'></a>wchar_t_assign_helper</b>
        <b>{</b>
        <font color='#0000FF'>public</font>:
            <b><a name='wchar_t_assign_helper'></a>wchar_t_assign_helper</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>wchar_t</u></font><font color='#5555FF'>*</font> str_
            <font face='Lucida Console'>)</font> : str<font face='Lucida Console'>(</font>str_<font face='Lucida Console'>)</font> <b>{</b><b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
            <b><a name='operator'></a>operator</b> <b><a name='T'></a>T</b> <font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>return</font> string_cast<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
            <b>}</b>

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>wchar_t</u></font><font color='#5555FF'>*</font> str;
        <b>}</b>;

    <font color='#009900'>// -------------
</font>
    <font color='#0000FF'>public</font>:

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> charT,
            <font color='#0000FF'>typename</font> traits,
            <font color='#0000FF'>typename</font> alloc
            <font color='#5555FF'>&gt;</font>
        string_assign_helper<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#0000FF'>return</font> string_assign_helper<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
        <b>}</b>

        char_assign_helper <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> 
        <b>{</b>
            <font color='#0000FF'>return</font> <font color='#BB00BB'>char_assign_helper</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
        <b>}</b>

        wchar_t_assign_helper <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>wchar_t</u></font><font color='#5555FF'>*</font> str
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> 
        <b>{</b>
            <font color='#0000FF'>return</font> <font color='#BB00BB'>wchar_t_assign_helper</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>;

    <font color='#0000FF'>const</font> string_assign sa <font color='#5555FF'>=</font> <b><a name='string_assign'></a>string_assign</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='wrap_string'></a>wrap_string</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> first_pad <font color='#5555FF'>=</font> <font color='#979000'>0</font>,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rest_pad <font color='#5555FF'>=</font> <font color='#979000'>0</font>,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> max_per_line <font color='#5555FF'>=</font> <font color='#979000'>79</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> first_pad <font color='#5555FF'>&lt;</font> max_per_line <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rest_pad <font color='#5555FF'>&lt;</font> max_per_line <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                 rest_pad <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> first_pad,
                 "<font color='#CC0000'>\tconst std::basic_string&lt;charT,traits,alloc&gt; wrap_string()</font>"
                 <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tfirst_pad:    </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> first_pad
                 <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trest_pad:     </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> rest_pad
                 <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tmax_per_line: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> max_per_line  <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;

        basic_ostringstream<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> sout;
        basic_istringstream<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>sin</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> rest_pad; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> </font>"<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>pad</font><font face='Lucida Console'>(</font>sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> first_pad; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> </font>"<font face='Lucida Console'>)</font>;


        <font color='#0000FF'>typename</font> basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>::size_type remaining <font color='#5555FF'>=</font> max_per_line <font color='#5555FF'>-</font> rest_pad;

        basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> temp;

        sin <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> temp;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>sin<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> remaining<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> rest_pad <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> max_per_line<font face='Lucida Console'>)</font>
                <b>{</b>
                    string::size_type i <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; i <font color='#5555FF'>&lt;</font> temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                    <b>{</b>
                        sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> temp[i];
                        <font color='#5555FF'>-</font><font color='#5555FF'>-</font>remaining;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>remaining <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                        <b>{</b>
                            sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'>\n</font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> pad;
                            remaining <font color='#5555FF'>=</font> max_per_line <font color='#5555FF'>-</font> rest_pad;
                        <b>}</b>
                    <b>}</b>
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'>\n</font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> pad <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> temp;
                    remaining <font color='#5555FF'>=</font> max_per_line <font color='#5555FF'>-</font> rest_pad <font color='#5555FF'>-</font> temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> remaining<font face='Lucida Console'>)</font>
            <b>{</b>
                sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> temp;
                remaining <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> temp;
                remaining <font color='#5555FF'>-</font><font color='#5555FF'>=</font> temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            sin <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> temp;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>remaining <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> sin<font face='Lucida Console'>)</font>
            <b>{</b>
                sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'>\n</font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> pad;
                remaining <font color='#5555FF'>=</font> max_per_line <font color='#5555FF'>-</font> rest_pad;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> </font>"<font face='Lucida Console'>)</font>;
                <font color='#5555FF'>-</font><font color='#5555FF'>-</font>remaining;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>return</font> sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT<font color='#5555FF'>&gt;</font> <b><a name='wrap_string'></a>wrap_string</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> str,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> first_pad <font color='#5555FF'>=</font> <font color='#979000'>0</font>,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rest_pad <font color='#5555FF'>=</font> <font color='#979000'>0</font>,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> max_per_line <font color='#5555FF'>=</font> <font color='#979000'>79</font>
    <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>wrap_string</font><font face='Lucida Console'>(</font>std::basic_string<font color='#5555FF'>&lt;</font>charT<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>,first_pad,rest_pad,max_per_line<font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='ltrim'></a>ltrim</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> trim_chars 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typedef</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> string;
        <font color='#0000FF'>typename</font> string::size_type pos <font color='#5555FF'>=</font> str.<font color='#BB00BB'>find_first_not_of</font><font face='Lucida Console'>(</font>trim_chars<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> string::npos<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>pos<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            <font color='#0000FF'>return</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='ltrim'></a>ltrim</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> trim_chars <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> \t\r\n</font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>ltrim</font><font face='Lucida Console'>(</font>str,std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>trim_chars<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='rtrim'></a>rtrim</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> trim_chars 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typedef</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> string;

        <font color='#0000FF'>typename</font> string::size_type pos <font color='#5555FF'>=</font> str.<font color='#BB00BB'>find_last_not_of</font><font face='Lucida Console'>(</font>trim_chars<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> string::npos<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            <font color='#0000FF'>return</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='rtrim'></a>rtrim</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> trim_chars <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> \t\r\n</font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>rtrim</font><font face='Lucida Console'>(</font>str,std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>trim_chars<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='trim'></a>trim</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> trim_chars 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typedef</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> string;
        <font color='#0000FF'>typename</font> string::size_type lpos <font color='#5555FF'>=</font> str.<font color='#BB00BB'>find_first_not_of</font><font face='Lucida Console'>(</font>trim_chars<font face='Lucida Console'>)</font>; 
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lpos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> string::npos<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>typename</font> string::size_type rpos <font color='#5555FF'>=</font> str.<font color='#BB00BB'>find_last_not_of</font><font face='Lucida Console'>(</font>trim_chars<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>lpos,rpos<font color='#5555FF'>-</font>lpos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'>return</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='trim'></a>trim</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> trim_chars <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> \t\r\n</font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>trim</font><font face='Lucida Console'>(</font>str,std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>trim_chars<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='rpad'></a>rpad</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'><u>long</u></font> pad_length,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> pad_string 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typedef</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> string;
        <font color='#009900'>// if str is too big then just return str
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pad_length <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> str;

        <font color='#009900'>// make the string we will padd onto the string
</font>        string P;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>P.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> pad_length <font color='#5555FF'>-</font> str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            P <font color='#5555FF'>+</font><font color='#5555FF'>=</font> pad_string;
        P <font color='#5555FF'>=</font> P.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,pad_length <font color='#5555FF'>-</font> str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// return the padded string
</font>        <font color='#0000FF'>return</font> str <font color='#5555FF'>+</font> P;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='rpad'></a>rpad</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'><u>long</u></font> pad_length,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> pad_string <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> </font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>rpad</font><font face='Lucida Console'>(</font>str,pad_length,std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>pad_string<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='lpad'></a>lpad</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'><u>long</u></font> pad_length,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> pad_string 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typedef</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> string;
        <font color='#009900'>// if str is too big then just return str
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pad_length <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> str;

        <font color='#009900'>// make the string we will padd onto the string
</font>        string P;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>P.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> pad_length <font color='#5555FF'>-</font> str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            P <font color='#5555FF'>+</font><font color='#5555FF'>=</font> pad_string;
        P <font color='#5555FF'>=</font> P.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,pad_length <font color='#5555FF'>-</font> str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// return the padded string
</font>        <font color='#0000FF'>return</font> P <font color='#5555FF'>+</font> str;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='lpad'></a>lpad</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'><u>long</u></font> pad_length,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> pad_string <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> </font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>lpad</font><font face='Lucida Console'>(</font>str,pad_length,std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>pad_string<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='pad'></a>pad</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'><u>long</u></font> pad_length,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> pad_string 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> str_size <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> <font color='#BB00BB'>rpad</font><font face='Lucida Console'>(</font><font color='#BB00BB'>lpad</font><font face='Lucida Console'>(</font>str,<font face='Lucida Console'>(</font>pad_length<font color='#5555FF'>-</font>str_size<font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font> <font color='#5555FF'>+</font> str_size,pad_string<font face='Lucida Console'>)</font>,  
                    pad_length, 
                    pad_string<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='pad'></a>pad</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'><u>long</u></font> pad_length,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> pad_string <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> </font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>pad</font><font face='Lucida Console'>(</font>str,pad_length,std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>pad_string<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='left_substr'></a>left_substr</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> delim 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,str.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>delim<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='left_substr'></a>left_substr</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> delim <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> \n\r\t</font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,str.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>delim<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='right_substr'></a>right_substr</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> delim 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>::size_type delim_pos <font color='#5555FF'>=</font> str.<font color='#BB00BB'>find_last_of</font><font face='Lucida Console'>(</font>delim<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>delim_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>::npos<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>delim_pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            <font color='#0000FF'>return</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <b><a name='right_substr'></a>right_substr</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> delim <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> \n\r\t</font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>::size_type delim_pos <font color='#5555FF'>=</font> str.<font color='#BB00BB'>find_last_of</font><font face='Lucida Console'>(</font>delim<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>delim_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>::npos<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>delim_pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            <font color='#0000FF'>return</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    std::pair<font color='#5555FF'>&lt;</font>std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>, std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> 
    <b><a name='split_on_first'></a>split_on_first</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> delim <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> \n\r\t</font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>::size_type delim_pos <font color='#5555FF'>=</font> str.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>delim<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>delim_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>::npos<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> std::<font color='#BB00BB'>make_pair</font><font face='Lucida Console'>(</font>str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>, delim_pos<font face='Lucida Console'>)</font>, str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>delim_pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            <font color='#0000FF'>return</font> std::<font color='#BB00BB'>make_pair</font><font face='Lucida Console'>(</font>str, <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> std::pair<font color='#5555FF'>&lt;</font>std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>, std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> 
    <b><a name='split_on_first'></a>split_on_first</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> delim 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>split_on_first</font><font face='Lucida Console'>(</font>str, delim.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    std::pair<font color='#5555FF'>&lt;</font>std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>, std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> 
    <b><a name='split_on_last'></a>split_on_last</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> delim <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> \n\r\t</font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typename</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>::size_type delim_pos <font color='#5555FF'>=</font> str.<font color='#BB00BB'>find_last_of</font><font face='Lucida Console'>(</font>delim<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>delim_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>::npos<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> std::<font color='#BB00BB'>make_pair</font><font face='Lucida Console'>(</font>str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>, delim_pos<font face='Lucida Console'>)</font>, str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>delim_pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            <font color='#0000FF'>return</font> std::<font color='#BB00BB'>make_pair</font><font face='Lucida Console'>(</font>str, <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> std::pair<font color='#5555FF'>&lt;</font>std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font>, std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> 
    <b><a name='split_on_last'></a>split_on_last</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> delim 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>split_on_last</font><font face='Lucida Console'>(</font>str, delim.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <b><a name='split'></a>split</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> delim <font color='#5555FF'>=</font> <font color='#BB00BB'>_dT</font><font face='Lucida Console'>(</font>charT,"<font color='#CC0000'> \n\r\t</font>"<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> temp;

        std::vector<font color='#5555FF'>&lt;</font>std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> res;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// check if delim contains the character str[i]
</font>            <font color='#0000FF'><u>bool</u></font> hit <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <font color='#0000FF'>const</font> charT<font color='#5555FF'>*</font> d <font color='#5555FF'>=</font> delim;
            <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>d <font color='#5555FF'>!</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\0</font>'<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>str[i] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>*</font>d<font face='Lucida Console'>)</font>
                <b>{</b>
                    hit <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                    <font color='#0000FF'>break</font>;
                <b>}</b>
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>d;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>hit<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    res.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
                    temp.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                temp.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>str[i]<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            res.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> res;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> charT,
        <font color='#0000FF'>typename</font> traits,
        <font color='#0000FF'>typename</font> alloc
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <b><a name='split'></a>split</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> str,
        <font color='#0000FF'>const</font> std::basic_string<font color='#5555FF'>&lt;</font>charT,traits,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> delim 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>split</font><font face='Lucida Console'>(</font>str,delim.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font> <b><a name='split'></a>split</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> delim <font color='#5555FF'>=</font> "<font color='#CC0000'> \n\r\t</font>"
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>split</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>,delim<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_STRINg_
</font>

</pre></body></html>